package com.promis.party.ui.home.homebanner.questionwall;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.promis.compat.StatusBarCompat;
import com.promis.party.R;
import com.promis.party.helper.ContextHelper;
import com.promis.party.helper.UIHepler;
import com.promis.util.StringUtils;
import com.promis.widget.recycler.LinearSpacingItemDecoration;
import com.promis.widget.recycler.RecyclerLayoutManagerHelper;

/**
 * Created by zcy on 2018/9/25.
 */

public class MyQuestionsDetailActivity extends AppCompatActivity {

    private ContextHelper contextHelper;

    private LinearLayout llyvSubmit;
    private TextView txtvSubmit;
    private EditText etxtvAnswer;
    private LinearLayout llyvEvaluate;

    private RecyclerView recyclerView;
    private QuestionAnswerListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarCompat.translucentStatusBar(this);
        StatusBarCompat.blackTextStatusBar(this);
        setContentView(R.layout.activity_my_questions_detail);
        UIHepler.goBack(MyQuestionsDetailActivity.this, R.id.activity_my_questions_detail_imgv_back);

        llyvSubmit = findViewById(R.id.activity_my_questions_detail_llyv_submit);
        txtvSubmit = findViewById(R.id.activity_my_questions_detail_txtv_submit);
        etxtvAnswer = findViewById(R.id.activity_my_questions_detail_txtv_content);
        recyclerView = findViewById(R.id.activity_my_questions_detail_rcyv);
        llyvEvaluate = findViewById(R.id.activity_my_questions_detail_llyv_evaluate);

        initData();
        initListener();
    }

    private void initData() {
        contextHelper = new ContextHelper(getBaseContext());
        if(getIntent().hasExtra("myQuestion")){
            llyvSubmit.setVisibility(View.VISIBLE);
            recyclerView.setVisibility(View.GONE);
            llyvEvaluate.setVisibility(View.GONE);
        }else{
            llyvSubmit.setVisibility(View.GONE);
            recyclerView.setVisibility(View.VISIBLE);
            llyvEvaluate.setVisibility(View.VISIBLE);
        }

        RecyclerLayoutManagerHelper.buildVerticalLinearLayoutManager(getBaseContext(), recyclerView);
        recyclerView.addItemDecoration(new LinearSpacingItemDecoration(getBaseContext(), LinearLayoutManager.VERTICAL, 15, R.color.split_line));
        adapter = new QuestionAnswerListAdapter(getBaseContext());
        recyclerView.setAdapter(adapter);
    }

    private void initListener() {
        txtvSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(StringUtils.isNullOrEmpty(etxtvAnswer.getText().toString())){
                    Toast.makeText(getBaseContext(), "回复不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                finish();
            }
        });
    }

//    public void httpFindDynamicList() {
//        HttpJsonParams params = new HttpJsonParams();
//        params.add("interest",1);
//        if (UserPreferences.getInstance(getContext()).exists()) {
//            params.add("userId", UserPreferences.getInstance(getContext()).getId());
//        }
//        String url = contextHelper.getServiceUrl(R.string.findInterestDynamicList);
//        new HttpClient<JsonList<Dynamic>>(getContext()) {
//            @Override
//            protected void onSuccess(JsonList<Dynamic> result) {
//                dynamicList = result.getDataList();
//                adptAdopt.notifyDataSetChanged(dynamicList);
//            }
//        }.postAsyn(url, params);
//    }
}